﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Business.IManager;
using Business.Manager;

namespace OnlinePayment.OP
{
    public partial class PayUtilityView : System.Web.UI.Page
    {
        Student stu;
        IUtilityPaymentManager utilityPaymentManager = new UtilityPaymentManager();
        IOrderManager orderManager = new OrderManager();
        public UtilityPaymentProject project;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (!object.Equals(Session["User"], null))
                {
                    stu = (Student)Session["User"];
                }

               
                
                UtilityPaymentInforBind(stu.StudentId);
            }
        }


        public void UtilityPaymentInforBind(string stuId)
        {
            lblStuID.Text = stuId;
            project = utilityPaymentManager.getUtilityPayment(stuId);
            if (object.Equals(project,null))
            {
                lblDormitory.Text = utilityPaymentManager.getStuDormitoryId(stuId);



                return;
            }


            hid_id.Value = project.Id.ToString();
            decimal totalAmount = project.WaterBill + project.ElectricityBill;
            if (totalAmount != 0)
            {
                lblSum.Text = totalAmount.ToString();
            }


            lblDormitory.Text = project.Dormitory.Address + " " + project.Dormitory.DormitoryNum;
            lblTime.Text = project.Date;
            lblLastWaterMeterNum.Text = Convert.ToString(project.LastWaterMeterNum);
            lblNowWaterMeterNum.Text = Convert.ToString(project.WaterMeterNum);
            lblWaterUsage.Text = Convert.ToString(project.WaterUsage);
            lblWaterUsageLimit.Text = Convert.ToString(project.WaterUsageLimit);
            lblNumBeyondWaterUsage.Text = Convert.ToString(project.WaterUsageBeyond);
            lblWaterPerPrice.Text = Convert.ToString(project.WaterPerPrice);
            lblWaterPrice.Text = Convert.ToString(project.WaterBill);
            lblTime1.Text = project.Date;
            lblLastElecMeterNum.Text = Convert.ToString(project.LastElecMeterNum);
            lblNowElecMeterNum.Text = Convert.ToString(project.ElecMeterNum);
            lblElecUsage.Text = Convert.ToString(project.ElectricityUsage);
            lblElecUsageLimit.Text = Convert.ToString(project.ElectricityUsageLimit);
            lblNumBeyondElecUsage.Text = Convert.ToString(project.ElectricityUsageBeyond);
            lblElecPerPrice.Text = Convert.ToString(project.ElectricityPerPrice);
            lblElecPrice.Text = Convert.ToString(project.ElectricityBill);
            lblSum.Text = Convert.ToString(project.WaterBill + project.ElectricityBill);

            if (lblSum.Text == "0")
            {
                //btnPay.Enabled = false;
            }
        }

        protected void btn_Pay_Click(object sender, EventArgs e)
        {
            UtilitiesHistoryOrder order = new UtilitiesHistoryOrder();
            order.OrderDate = System.DateTime.Now;
            order.TotalAmount = Decimal.Parse(lblSum.Text);
            order.PaymentType = "水电费";
            order.UtilityId = hid_id.Value.ToString();//project.Id.ToString();
            //order.OrderId = orderManager.getOrderId(order.PaymentType);
            
            Session["GoodsID"] = Convert.ToString(order.UtilityId);
            Session["Order"] = order;
            Response.Redirect("OrderConfirmView.aspx");
        }
    }
}